package com.special.ResideMenuDemo;

import java.util.ArrayList;
import java.util.List;

import com.zsl.bean.OrderBean;
import com.zsl.dao.OrderDao;
import com.zsl.dao.impl.OrderDaoImpl;
import com.zsl.order.adapter.TodayOrderAdapter;
import com.zsl.util.Util;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ListView;
import android.widget.TextView;

public class TodayActivity extends Activity {

	
	private ListView lv_order;
	private TextView tv_money;
	private TodayOrderAdapter adapter;
	private List<OrderBean> beans=new ArrayList<OrderBean>();
	
	private Handler handler;
	private List<OrderBean> list=new ArrayList<OrderBean>();
	
	private static final OrderDao orderDao=MainActivity.getOrderDao();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.today_order);		
		lv_order=(ListView) findViewById(R.id.today_order_listView1);
		tv_money=(TextView) findViewById(R.id.today_order_money);
		String time=new Util().getNowTime();
		list=orderDao.findAllByToday(time);
		adapter=new TodayOrderAdapter(this, list);
		lv_order.setAdapter(adapter);
		adapter.notifyDataSetChanged();
		handler=new Handler(){
			public void handleMessage(android.os.Message msg) {
				switch (msg.what) {
				case 1:
				{
					beans=(List<OrderBean>) msg.obj;
					adapter.notifyDataSetChanged();
				}
				break;
				default:
					break;
				}
			};
		};
		int todayMoney=0;
		for (int i = 0; i < list.size(); i++) {
			String money=list.get(i).getMoney();
			int orderMoney=Integer.parseInt(money);
			todayMoney+=orderMoney;
		}
		
		tv_money.setText(todayMoney+"");
		//启动查询
//		new Thread(){
//			public void run() {
//				String time=new Util().getNowTime();
//				List<OrderBean> list=orderDao.findAllByToday(time);
//				Message message=new Message();
//				message.obj=list;
//				message.what=1;
//				handler.sendMessage(message);
//				
//			};
//		}.start();
		
	}
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		this.finish();
		super.onBackPressed();
		
	}
	
}
